package com.demo.TDengine.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.TDengine.domain.Water;
import com.demo.TDengine.mapper.WaterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;

/**
 *  TD engine 测试
 * @author qkj
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private WaterMapper waterMapper;

    /**
     *  测试插入 （方便浏览器测试 这里使用get请求）
     * @return
     */
    @GetMapping
    public String test() {
        waterMapper.insertOne(new Water().setPhase(1.0F).setTs(Timestamp.valueOf(LocalDateTime.now())));
        return "ok";
    }


    @GetMapping("/list")
    public List<Water> getList() {

        Page page = new Page();
        page.setSize(2).setCurrent(1);
        List<Water> res = waterMapper.selectList(page);
        return res;
    }
}
